package com.acoffee.java1;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author acoffee
 * @create 2021-11-16 15:26
 */
@Aspect
@Component
public class CookieAspect {

    @Pointcut("execution(* com.acoffee.java1.Impl.*.*(..))")
    public void pointcut() {}

    @Before("pointcut()")
    public void log() {
        System.out.println("--------日志记录--------");
    }

    @AfterReturning("pointcut()")
    public void release() {
        System.out.println("--------释放资源--------");
    }

    @Around("pointcut()")
    public Object round(ProceedingJoinPoint joinPoint){
        Object obj = null;
        System.out.println("****之前****");
        try {
            obj = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("****之后****");
        return obj;
    }
}
